import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/home/board/get_message_entity.dart';
import 'package:safetymonitor/generated/assets.dart';

/// 公告详情
class BoardDetails extends StatefulWidget {
  const BoardDetails({super.key});

  @override
  State<BoardDetails> createState() => _BoardDetailsState();
}

class _BoardDetailsState extends State<BoardDetails> {

  GetMessageEntity get message => Get.arguments as GetMessageEntity;


  // 设置已阅读状态
  void _setReadStatus() async {
     await HttpUtil().generatePutRequest(Interface.putNoticeRead,queryParameters: {
      'ids':[message.id],
    }).execute();
  }

  @override
  void initState() {
    super.initState();
    _setReadStatus();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_page_color,
      appBar: CustomAppBar(
        titleText: '通知公告',
      ),
      body: Container(
        margin: EdgeInsets.all(16.w),
        padding: const EdgeInsets.symmetric(vertical: 16),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16),
              child: Column(
                children: [
                  Row(
                    children: [
                      SvgPicture.asset(Assets.svgMessageList),
                      AppGaps.hGap10,
                      Expanded(
                        child: Text(
                          '${message.title}',
                          style: TextStyle(
                            color: Colors.black,
                            fontSize: 18.sp,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                    ],
                  ),
                  AppGaps.vGap10,
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '${DateTime.fromMillisecondsSinceEpoch(int.tryParse(message.createTime ?? '0') ?? 0)}',
                      style: TextStyle(
                        color: const Color(0xffC7CEE5),
                        fontSize: 14.sp,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            AppGaps.vGap12,
            Container(
              height: 1,
              color: AppColors.divider_color,
            ),
            Expanded(
                child: Container(
              padding: const EdgeInsets.all(16),
              child: SingleChildScrollView(
                child: Text(
                  '${message.templateContent}',
                  style: TextStyles.black_14,
                ),
              ),
            ))
          ],
        ),
      ),
    );
  }
}
